home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / chatInviteBuddy.js < prev    next >
Encoding:
Text File  |  2002-02-08  |  11.5 KB  |  301 lines

  1. // globals
  2. // window arguments defined here, but may not be used.
  3. // mainly to test & explain valid arguments.
  4.  
  5. /**
  6. var invitedScreenNames = window.arguments[0]
  7. var inviteToExistingWindow=window.arguments[1]
  8. var inviteMode=window.arguments[2]
  9. var inviteProposalObj=window.arguments[3]
  10. **/
  11.  
  12. inviteArgsObj = window.arguments[0];
  13.  
  14. invitedScreenNames        = inviteArgsObj.invitedScreenNames;
  15. inviteToExistingWindow    = inviteArgsObj.inviteToExistingWindow;
  16. inviteMode                = inviteArgsObj.inviteMode;
  17. inviteMsg                 = inviteArgsObj.invitationmsg;
  18. inviteProposalObj         = inviteArgsObj.inviteProposalObj;
  19. inviteProposalScreenName  = inviteArgsObj.inviteProposalScreenName;
  20. inviteToExistingRoom      = inviteArgsObj.inviteToExistingRoom;
  21.  
  22. // for incoming chat invitation
  23. var incomingChatScreenName = inviteProposalScreenName;
  24. var incomingChatWarningLevel;
  25. var incomingChatRoomName;
  26. var incomingChatRoomDate;
  27. var incomingChatRoomInviteMsg;
  28. var incomingChatRoom;
  29.  
  30. var ChatManagerCallBack = new Object();
  31. var RoomCreationTimeStamp = null;
  32.  
  33. ChatManagerCallBack.OnRequestRoomComplete =  function(roomName,chatRoomObj)
  34. {
  35.    incomingChatRoom=chatRoomObj;
  36.    incomingChatRoomName = chatRoomObj.GetName();
  37.    document.getElementById("chatRendezvousRoomName001").setAttribute("value",incomingChatRoomName);   
  38. }
  39.  
  40. ChatManagerCallBack.OnRequestRoomError =  function(roomName,errMsg)
  41. {
  42.    dump("OnRequestRoomError: there was an error \n");
  43. }
  44.  
  45. myExecutionCallback = new Object();
  46. myExecutionCallback.ExecuteIfReady = function()
  47. {
  48.    // get chatroom and callbacks
  49.    inviteProposalObj.Accept();
  50.    aimChatManager().RequestProposedRoom(ChatManagerCallBack, inviteProposalObj);
  51. }
  52.  
  53. function setButtons(okLabel, cancelLabel, okTooltip, cancelTooltip)
  54. {
  55.   var buttons = document.getElementsByTagName("button");
  56.   for (i=0;i<buttons.length;i++) {
  57.    //dump("buttons["+i+"] = " + buttons[i] + "," + buttons[i].getAttribute('id') + "\n");
  58.    if (okLabel && buttons[i].getAttribute('id') == "ok") {
  59.      buttons[i].label = okLabel;
  60.    }
  61.    else if (cancelLabel && buttons[i].getAttribute('id') == "cancel") {
  62.      buttons[i].label = cancelLabel;
  63.    }
  64.    /**  killing tooltips for ok cancel for now since they are text 
  65.    if(okTooltip && buttons[i].getAttribute('id') == "ok") {
  66.      buttons[i].setAttribute('tooltip','aTooltip');
  67.      buttons[i].setAttribute('tooltiptext', okTooltip);
  68.    }
  69.  
  70.    if(cancelTooltip && buttons[i].getAttribute('id') == "cancel") {
  71.      buttons[i].setAttribute('tooltip','aTooltip');
  72.      buttons[i].setAttribute('tooltiptext', cancelTooltip);
  73.    }
  74.    **/
  75.   }
  76. }
  77.  
  78. function chatInviteBuddyOnWinLoad(){
  79.    doSetOKCancel(chatInviteBuddyCmdInvite, onCancel);
  80.  
  81.    /* VISHY - this is a performance optimization. 
  82.       Since chat needs time to get ready, this tells it to 
  83.       get ready, well before we actually use it */
  84.    aimChatManager().ExecuteIfReady(null);
  85.  
  86.    dump("chatInviteBuddyOnWinLoad\n");
  87.  
  88.    if(inviteMode && inviteMode=="incomingchat"){
  89.      setButtons(aimString('chat.YesButton'), aimString('chat.NoButton'), aimString('accept.tooltip'), aimString('decline.tooltip'));
  90.     
  91.       dump("incoming chat\n");
  92.  
  93.       doSetOKCancel(chatInviteBuddyCmdAcceptRendezvous, chatInviteBuddyCmdDeclineRendezvous);
  94.  
  95.       document.getElementById("cibdeck001").setAttribute("selectedIndex",2)
  96.  
  97.    // incomingChatScreenName = "testscreename";
  98.       incomingChatWarningLevel =  " " + aimString("chat.WarningLevel").replace(/%Level%/, inviteProposalObj.GetProposer().GetWarningPercent());
  99.       incomingChatRoomName = " ";
  100.       incomingChatRoomDate= new Date();
  101.  
  102.     // use international date format
  103.     try {
  104.          var IDateTime = Components.classes["@mozilla.org/intl/scriptabledateformat;1"].createInstance();
  105.          var dateFormatter = IDateTime.QueryInterface(Components.interfaces.nsIScriptableDateFormat);
  106.          
  107.          var curYear = incomingChatRoomDate.getYear() + 1900;
  108.          var curMonth = incomingChatRoomDate.getMonth() + 1;
  109.          var curDay = incomingChatRoomDate.getDate();
  110.          var curHours = incomingChatRoomDate.getHours();
  111.          var curMinutes = incomingChatRoomDate.getMinutes();
  112.          var curSeconds = incomingChatRoomDate.getSeconds();
  113.          dump("stuff: " + curYear + " " + curMonth + " " +curDay + " " +curHours + " " +curMinutes + " " +curSeconds + "\n");
  114.  
  115.          dateTimeStr = dateFormatter.FormatDateTime("",
  116.             Components.interfaces.nsIScriptableDateFormat.dateFormatLong,
  117.             Components.interfaces.nsIScriptableDateFormat.timeFormatSeconds,
  118.             curYear,curMonth,curDay,curHours,curMinutes,curSeconds);
  119.          incomingChatRoomDate = dateTimeStr;
  120.          dump("Using FormatDateTime: " + incomingChatRoomDate + "\n");
  121.       }
  122.     catch(e) {
  123.       dump("Error using FormatDateTime: " + e + "\n");
  124.     }
  125.  
  126.       incomingChatRoomInviteMsg = inviteProposalObj.GetInvitation();
  127.       document.getElementById("chatRendezvousScreenName001").setAttribute("value",incomingChatScreenName);
  128.       document.getElementById("chatRendezvousScreenName002").setAttribute("label",incomingChatScreenName);
  129.       document.getElementById("chatRendezvousScreenName003").setAttribute("value",incomingChatScreenName);
  130.       document.getElementById("chatRendezvousWarningLevel001").setAttribute("value",incomingChatWarningLevel);
  131.       document.getElementById("chatRendezvousRoomName001").setAttribute("value",incomingChatRoomName);
  132.       document.getElementById("chatRendezvousChatRoomDate").setAttribute("value",incomingChatRoomDate);
  133.       document.getElementById("chatRendezvousInvitationMsg").setAttribute("value", incomingChatRoomInviteMsg);
  134.       
  135.       //XXXVISHY - unfortunately you need to get the Chat Room 
  136.       // in order to find its name ;-)
  137.       aimChatManager().ExecuteIfReady(myExecutionCallback);
  138.    }
  139.  
  140.    if(inviteMode && inviteMode=="outgoingchat")
  141.    {
  142.       dump("outgoing chat\n");
  143.       setButtons(aimString('chat.InviteButton'), null, aimString('chatInvite.tooltip'), aimString('chatCancel.tooltip'));
  144.     
  145.       document.getElementById("cibdeck001").setAttribute("selectedIndex",1)
  146.       
  147.       if (invitedScreenNames && invitedScreenNames != ""){}
  148.       else
  149.       {
  150.          invitedScreenNames = "";
  151.          document.getElementById("invitedscreennames").focus();
  152.       }
  153.  
  154.       document.getElementById("invitedscreennames").value = invitedScreenNames;
  155.       if(inviteMsg)
  156.          document.getElementById("invitationmsg").value=inviteMsg;
  157.       else
  158.          document.getElementById("invitationmsg").value=aimString("chat.JoinMe");
  159.       
  160.       if(inviteToExistingRoom)
  161.       {
  162.          dump("inviteToExisting Room\n");
  163.          document.getElementById("buddychatroomname").value = inviteToExistingRoom;
  164.          document.getElementById("buddychatroomname").setAttribute("readonly","true");
  165.       }
  166.       else
  167.          chatPreFillRoomName();
  168.    }
  169.  
  170. }
  171.  
  172. function onCancel(){
  173.    return true;
  174. }
  175.  
  176. function chatInviteBuddyOnWinUnLoad(){
  177.    //window.close();
  178. }
  179.  
  180. function chatInviteBuddyCmdInvite(){
  181.    dump("chatInviteBuddyCmdIncite\n");
  182.       document.getElementById("cibdeck001").setAttribute("selectedIndex",3)
  183.  
  184.    // document.getElementById("cibdeck").setAttribute("id",1);
  185.    if(!inviteToExistingWindow){
  186.    // var invitedScreenNames = document.getElementById("invitedscreennames").getAttribute("value");
  187.       var invitedScreenNames = document.getElementById("invitedscreennames").value;
  188.    // var chatRoomName = document.getElementById("buddychatroomname").getAttribute("value");
  189.       var chatRoomName = document.getElementById("buddychatroomname").value;
  190.       dump("setting ChatRoomName "+chatRoomName+"\n")
  191.    // var chatMsg = document.getElementById("invitationmsg").getAttribute("value");
  192.       var chatMsg = document.getElementById("invitationmsg").value;
  193.       dump("screenNames "+invitedScreenNames+"\n");
  194.       
  195.       // just send one argument to window.openDialog - but build an object. This way you dont have to worry about
  196.       // keeping track of the argument's order.
  197.       chatContentArgs = new Object();
  198.       chatContentArgs.invitedScreenNames = invitedScreenNames;
  199.       chatContentArgs.chatRoomName = chatRoomName;
  200.       chatContentArgs.chatMsg = chatMsg;
  201.       // not incoming chat
  202.       chatContentArgs.incomingChat = false;
  203.       chatContentArgs.incomingChatInviteProposalScreenName = ''
  204.       chatContentArgs.incomingChatInviteProposalObj=null
  205.       chatContentArgs.incomingChatRoom=null;
  206.       dump("about to openDialog chatContent.xul\n");
  207.       window.openDialog("chrome://aim/content/chatContent.xul","","chrome,all,dialog=no",chatContentArgs);
  208.  
  209.       
  210.       //window.close();
  211.  
  212.    }
  213.    else{
  214.       dump("myOpener:"+window.opener+"\n")
  215.    // window.opener.chatContentInviteMany(document.getElementById("invitedscreennames").getAttribute("value"),document.getElementById("invitationmsg").getAttribute("value"))
  216.       window.opener.chatContentInviteMany(document.getElementById("invitedscreennames").value,document.getElementById("invitationmsg").value);
  217.    // window.opener.chatMsg = document.getElementById("invitationmsg").getAttribute("value")
  218.       window.opener.chatMsg = document.getElementById("invitationmsg").value;
  219.       window.close();
  220.    }
  221.  
  222. }
  223.  
  224. function cmdChatIncomingWarn()
  225. {
  226.     var warnUserArgs = new Object();
  227.     warnUserArgs.screenName = incomingChatScreenName;
  228.     
  229.     window.openDialog("chrome://aim/content/WarnUser.xul","_blank", "chrome,dialog=no",warnUserArgs)
  230. }
  231.  
  232. function cmdChatIncomingBlock()
  233. {
  234.    var pIAimPrivacy = aimPrivacy();
  235.    if ( !pIAimPrivacy )
  236.       return false;
  237.  
  238.    pIAimPrivacy.BlockUser( incomingChatScreenName );
  239.    inviteProposalObj.Reject();
  240.     window.close();
  241. }
  242.  
  243. function cmdChatIncomingIM()
  244. {
  245.     aimIMInvokeIMForm(incomingChatScreenName);
  246. }
  247.  
  248. function cmdChatIncomingInfo()
  249. {
  250.  
  251. }
  252.  
  253. function chatInviteBuddyCmdDeclineRendezvous()
  254. {
  255.    inviteProposalObj.Reject();
  256.    window.close();
  257. }
  258.  
  259. function chatInviteBuddyCmdAcceptRendezvous(){
  260.       document.getElementById("cibdeck001").setAttribute("selectedIndex",3)
  261.  
  262.  
  263.    // code to accept rendezvous here
  264.    var invitedScreenNames = "";
  265.    var chatRoomName=incomingChatRoomName
  266.    var chatMsg = "";
  267.  
  268.  
  269.    // just send one argument to window.openDialog - but build an object. This way you dont have to worry about
  270.    // keeping track of the argument's order.
  271.    chatContentArgs = new Object();
  272.    chatContentArgs.invitedScreenNames = invitedScreenNames;
  273.    chatContentArgs.chatRoomName = chatRoomName;
  274.    chatContentArgs.chatMsg = chatMsg;
  275.    dump('chatInviteBuddy.js :try to accept the proposal \n');
  276. // inviteProposalObj.Accept();
  277. // yes incoming chat
  278.    chatContentArgs.incomingChat = true;
  279.    chatContentArgs.incomingChatInviteProposalScreenName = inviteProposalScreenName;
  280.    chatContentArgs.incomingChatInviteProposalObj=inviteProposalObj
  281.    chatContentArgs.incomingChatRoom=incomingChatRoom;
  282.    window.openDialog("chrome://aim/content/chatContent.xul","","chrome,all,dialog=no",chatContentArgs);
  283.    
  284.  
  285. }
  286.  
  287.  
  288. function chatPreFillRoomName(){
  289.    if(aimManager()){
  290.       // depends on AimSession.js
  291.       var currentScreenName = aimSessionCurrentScreenName()
  292.       // does this need to be instead 001 , 002, 003 ?
  293.       var someRandomNumber = Math.ceil(Math.random()*100);
  294.       // document.getElementById("buddychatroomname").setAttribute("value",currentScreenName+" chat "+someRandomNumber);
  295.       document.getElementById("buddychatroomname").value=currentScreenName+" chat "+someRandomNumber;
  296.  
  297.    }
  298.  
  299. }
  300.  
  301.